const TOKEN_KEY = 'qingbook_token'
const USER_KEY = 'qingbook_user'

// 获取token
export const getToken = () => {
  return localStorage.getItem(TOKEN_KEY)
}

// 设置token
export const setToken = (token) => {
  localStorage.setItem(TOKEN_KEY, token)
}

// 移除token
export const removeToken = () => {
  localStorage.removeItem(TOKEN_KEY)
}

// 获取用户信息
export const getUserInfo = () => {
  const userInfo = localStorage.getItem(USER_KEY)
  return userInfo ? JSON.parse(userInfo) : null
}

// 设置用户信息
export const setUserInfo = (userInfo) => {
  localStorage.setItem(USER_KEY, JSON.stringify(userInfo))
}

// 移除用户信息
export const removeUserInfo = () => {
  localStorage.removeItem(USER_KEY)
}

// 检查是否登录
export const isAuthenticated = () => {
  return !!getToken()
}


// 新增：存储Token过期时间
export function setTokenExpiry(expiry) {
  localStorage.setItem('token_expiry', expiry)
}

// 新增：获取Token过期时间
export function getTokenExpiry() {
  return localStorage.getItem('token_expiry')
}

// 新增：清除Token过期时间
export function removeTokenExpiry() {
  localStorage.removeItem('token_expiry')
}